home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / wemdemo4.zip / INFO / LEMACS.8 (.txt) < prev    next >
GNU Info File  |  1994-09-21  |  49KB  |  869 lines

  1. This is Info file ../info/lemacs, produced by Makeinfo-1.55 from the
  2. input file lemacs.txi.
  3.    This file documents the GNU Emacs editor.
  4.    Copyright (C) 1985, 1986, 1988 Richard M. Stallman.  Copyright (C)
  5. 1991, 1992 Lucid, Inc.
  6.    Permission is granted to make and distribute verbatim copies of this
  7. manual provided the copyright notice and this permission notice are
  8. preserved on all copies.
  9.    Permission is granted to copy and distribute modified versions of
  10. this manual under the conditions for verbatim copying, provided also
  11. that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
  12. General Public License" are included exactly as in the original, and
  13. provided that the entire resulting derived work is distributed under the
  14. terms of a permission notice identical to this one.
  15.    Permission is granted to copy and distribute translations of this
  16. manual into another language, under the above conditions for modified
  17. versions, except that the sections entitled "The GNU Manifesto",
  18. "Distribution" and "GNU General Public License" may be included in a
  19. translation approved by the author instead of in the original English.
  20. File: lemacs,  Node: Words,  Next: Sentences,  Prev: Text Mode,  Up: Text
  21. Words
  22. =====
  23.    Emacs has commands for moving over or operating on words.  By
  24. convention, the keys for them are all `Meta-' characters.
  25. `M-f'
  26.      Move forward over a word (`forward-word').
  27. `M-b'
  28.      Move backward over a word (`backward-word').
  29. `M-d'
  30.      Kill up to the end of a word (`kill-word').
  31. `M-DEL'
  32.      Kill back to the beginning of a word (`backward-kill-word').
  33. `M-@'
  34.      Mark the end of the next word (`mark-word').
  35. `M-t'
  36.      Transpose two words;  drag a word forward or backward across other
  37.      words (`transpose-words').
  38.    Notice how these keys form a series that parallels the
  39. character-based `C-f', `C-b', `C-d', `C-t' and DEL.  `M-@' is related
  40. to `C-@', which is an alias for `C-SPC'.
  41.    The commands `Meta-f' (`forward-word') and `Meta-b'
  42. (`backward-word') move forward and backward over words.  They are
  43. analogous to `Control-f' and `Control-b', which move over single
  44. characters.  Like their `Control-' analogues, `Meta-f' and `Meta-b'
  45. move several words if given an argument.  `Meta-f' with a negative
  46. argument moves backward, and `Meta-b' with a negative argument moves
  47. forward.  Forward motion stop after the last letter of the word, while
  48. backward motion stops before the first letter.
  49.    `Meta-d' (`kill-word') kills the word after point.  To be precise,
  50. it kills everything from point to the place `Meta-f' would move to.
  51. Thus, if point is in the middle of a word, `Meta-d' kills just the part
  52. after point.  If some punctuation comes between point and the next
  53. word, it is killed along with the word.  (To kill only the next word
  54. but not the punctuation before it, simply type `Meta-f' to get the end,
  55. and kill the word backwards with `Meta-DEL'.) `Meta-d' takes arguments
  56. just like `Meta-f'.
  57.    `Meta-DEL' (`backward-kill-word') kills the word before point.  It
  58. kills everything from point back to where `Meta-b' would move to.  If
  59. point is after the space in `FOO, BAR', then `FOO, ' is killed.   To
  60. kill just `FOO', type `Meta-b Meta-d' instead of `Meta-DEL'.)
  61.    `Meta-t' (`transpose-words') exchanges the word before or containing
  62. point with the following word.  The delimiter characters between the
  63. words do not move.  For example, transposing `FOO, BAR' results in
  64. `BAR, FOO' rather than `BAR FOO,'.  *Note Transpose::, for more on
  65. transposition and on arguments to transposition commands.
  66.    To operate on the next N words with an operation which applies
  67. between point and mark, you can either set the mark at point and then
  68. move over the words, or you can use the command `Meta-@' (`mark-word')
  69. which does not move point, but sets the mark where `Meta-f' would move
  70. to.  It can be given arguments just like `Meta-f'.
  71.    The word commands' understanding of syntax is completely controlled
  72. by the syntax table.  Any character can, for example, be declared to be
  73. a word delimiter.  *Note Syntax::.
  74. File: lemacs,  Node: Sentences,  Next: Paragraphs,  Prev: Words,  Up: Text
  75. Sentences
  76. =========
  77.    The Emacs commands for manipulating sentences and paragraphs are
  78. mostly on `Meta-' keys, and therefore like the word-handling commands.
  79. `M-a'
  80.      Move back to the beginning of the sentence (`backward-sentence').
  81. `M-e'
  82.      Move forward to the end of the sentence (`forward-sentence').
  83. `M-k'
  84.      Kill forward to the end of the sentence (`kill-sentence').
  85. `C-x DEL'
  86.      Kill back to the beginning of the sentence
  87.      (`backward-kill-sentence').
  88.    The commands `Meta-a' and `Meta-e' (`backward-sentence' and
  89. `forward-sentence') move to the beginning and end of the current
  90. sentence, respectively.  They resemble `Control-a' and `Control-e',
  91. which move to the beginning and end of a line.  Unlike their
  92. counterparts, `Meta-a' and `Meta-e' move over successive sentences if
  93. repeated or given numeric arguments.  Emacs assumes the typist's
  94. convention is followed, and thus considers a sentence to end wherever
  95. there is a `.', `?' or `!' followed by the end of a line or two spaces,
  96. with any number of `)', `]', `'', or `"' characters allowed in between.
  97. A sentence also begins or ends wherever a paragraph begins or ends.
  98.    Neither `M-a' nor `M-e' moves past the newline or spaces beyond the
  99. sentence edge at which it is stopping.
  100.    `M-a' and `M-e' have a corresponding kill command, just like `C-a'
  101. and `C-e' have `C-k'.  The command is  `M-k' (`kill-sentence') which
  102. kills from point to the end of the sentence.  With minus one as an
  103. argument it kills back to the beginning of the sentence.  Larger
  104. arguments serve as repeat counts.
  105.    There is a special command, `C-x DEL' (`backward-kill-sentence') for
  106. killing back to the beginning of a sentence, which is useful when you
  107. change your mind in the middle of composing text.
  108.    The variable `sentence-end' controls recognition of the end of a
  109. sentence.  It is a regexp that matches the last few characters of a
  110. sentence, together with the whitespace following the sentence.  Its
  111. normal value is
  112.      "[.?!][]\"')]*\\($\\|\t\\|  \\)[ \t\n]*"
  113. This example is explained in the section on regexps.  *Note Regexps::.
  114. File: lemacs,  Node: Paragraphs,  Next: Pages,  Prev: Sentences,  Up: Text
  115. Paragraphs
  116. ==========
  117.    The Emacs commands for manipulating paragraphs are also `Meta-' keys.
  118. `M-['
  119.      Move back to previous paragraph beginning
  120.      (`backward-paragraph').
  121. `M-]'
  122.      Move forward to next paragraph end (`forward-paragraph').
  123. `M-h'
  124.      Put point and mark around this or next paragraph
  125.      (`mark-paragraph').
  126.    `Meta-[' moves to the beginning of the current or previous paragraph,
  127. while `Meta-]' moves to the end of the current or next paragraph.
  128. Blank lines and text formatter command lines separate paragraphs and are
  129. not part of any paragraph.  An indented line starts a new paragraph.
  130.    In major modes for programs (as opposed to Text mode), paragraphs
  131. begin and end only at blank lines.  As a result, the paragraph commands
  132. continue to be useful even though there are no paragraphs per se.
  133.    When there is a fill prefix, paragraphs are delimited by all lines
  134. which don't start with the fill prefix.  *Note Filling::.
  135.    To operate on a paragraph, you can use the command `Meta-h'
  136. (`mark-paragraph') to set the region around it.  This command puts
  137. point at the beginning and mark at the end of the paragraph point was
  138. in.  If point is between paragraphs (in a run of blank lines, or at a
  139. boundary), the paragraph following point is surrounded by point and
  140. mark.  If there are blank lines preceding the first line of the
  141. paragraph, one of the blank lines is included in the region.  Thus, for
  142. example, `M-h C-w' kills the paragraph around or after point.
  143.    The precise definition of a paragraph boundary is controlled by the
  144. variables `paragraph-separate' and `paragraph-start'.  The value of
  145. `paragraph-start' is a regexp that matches any line that either starts
  146. or separates paragraphs.  The value of `paragraph-separate' is another
  147. regexp that  matches only lines that separate paragraphs without being
  148. part of any paragraph.  Lines that start a new paragraph and are
  149. contained in it must match both regexps.  For example, normally
  150. `paragraph-start' is `"^[ \t\n\f]"' and `paragraph-separate' is `"^[
  151. \t\f]*$"'.
  152.    Normally it is desirable for page boundaries to separate paragraphs.
  153. The default values of these variables recognize the usual separator for
  154. pages.
  155. File: lemacs,  Node: Pages,  Next: Filling,  Prev: Paragraphs,  Up: Text
  156. Pages
  157. =====
  158.    Files are often thought of as divided into "pages" by the "formfeed"
  159. character (ASCII Control-L, octal code 014).  For example, if a file is
  160. printed on a line printer, each "page" of the file starts on a new page
  161. of paper.  Emacs treats a page-separator character just like any other
  162. character.  It can be inserted with `C-q C-l', or deleted with DEL.
  163. You are free to paginate your file or not.  However, since pages are
  164. often meaningful divisions of the file, commands are provided to move
  165. over them and operate on them.
  166. `C-x ['
  167.      Move point to previous page boundary (`backward-page').
  168. `C-x ]'
  169.      Move point to next page boundary (`forward-page').
  170. `C-x C-p'
  171.      Put point and mark around this page (or another page)
  172.      (`mark-page').
  173. `C-x l'
  174.      Count the lines in this page (`count-lines-page').
  175.    The `C-x [' (`backward-page') command moves point to immediately
  176. after the previous page delimiter.  If point is already right after a
  177. page delimiter, the command skips that one and stops at the previous
  178. one.  A numeric argument serves as a repeat count.  The `C-x ]'
  179. (`forward-page') command moves forward past the next page delimiter.
  180.    The `C-x C-p' command (`mark-page') puts point at the beginning of
  181. the current page and the mark at the end.  The page delimiter at the end
  182. is included (the mark follows it).  The page delimiter at the front is
  183. excluded (point follows it).  You can follow this command  by `C-w' to
  184. kill a page you want to move elsewhere.  If you insert the page after a
  185. page delimiter, at a place where `C-x ]' or `C-x [' would take you, the
  186. page will be properly delimited before and after once again.
  187.    A numeric argument to `C-x C-p' is used to specify which page to go
  188. to, relative to the current one.  Zero means the current page.  One
  189. means the next page, and -1 means the previous one.
  190.    The `C-x l' command (`count-lines-page') can help you decide where
  191. to break a page in two.  It prints the total number of lines in the
  192. current page in the echo area, then divides the lines into those
  193. preceding the current line and those following it, for example
  194.      Page has 96 (72+25) lines
  195. Notice that the sum is off by one; this is correct if point is not at
  196. the beginning of a line.
  197.    The variable `page-delimiter' should have as its value a regexp that
  198. matches the beginning of a line that separates pages.  This defines
  199. where pages begin.  The normal value of this variable is `"^\f"', which
  200. matches a formfeed character at the beginning of a line.
  201. File: lemacs,  Node: Filling,  Next: Case,  Prev: Pages,  Up: Text
  202. Filling Text
  203. ============
  204.    If you use Auto Fill mode, Emacs "fills" text (breaks it up into
  205. lines that fit in a specified width) as you insert it.  When you alter
  206. existing text it is often no longer be properly filled afterwards and
  207. you can use explicit commands for filling.
  208. * Menu:
  209. * Auto Fill::      Auto Fill mode breaks long lines automatically.
  210. * Fill Commands:: Commands to refill paragraphs and center lines.
  211. * Fill Prefix::   Filling when every line is indented or in a comment, etc.
  212. File: lemacs,  Node: Auto Fill,  Next: Fill Commands,  Prev: Filling,  Up: Filling
  213. Auto Fill Mode
  214. --------------
  215.    "Auto Fill" mode is a minor mode in which lines are broken
  216. automatically when they become too wide.  Breaking happens only when
  217. you type a SPC or RET.
  218. `M-x auto-fill-mode'
  219.      Enable or disable Auto Fill mode.
  220. `SPC'
  221. `RET'
  222.      In Auto Fill mode, break lines when appropriate.
  223.    `M-x auto-fill-mode' turns Auto Fill mode on if it was off, or off
  224. if it was on.  With a positive numeric argument the command always turns
  225. Auto Fill mode on, and with a negative argument it always turns it off.
  226. The presence of the word `Fill' in the mode line, inside the
  227. parentheses, indicates that Auto Fill mode is in effect.  Auto Fill mode
  228. is a minor mode; you can turn it on or off for each buffer individually.
  229. *Note Minor Modes::.
  230.    In Auto Fill mode, lines are broken automatically at spaces when
  231. they get longer than desired.  Line breaking and rearrangement takes
  232. place only when you type SPC or RET.  To insert a space or newline
  233. without permitting line-breaking, type `C-q SPC' or `C-q LFD' (recall
  234. that a newline is really a linefeed).  `C-o' inserts a newline without
  235. line breaking.
  236.    Auto Fill mode works well with Lisp mode: when it makes a new line in
  237. Lisp mode it indents that line with TAB.  If a line ending in a Lisp
  238. comment gets too long, the text of the comment is split into two
  239. comment lines.  Optionally new comment delimiters are inserted at the
  240. end of the first line and the beginning of the second, so that each line
  241. is a separate comment.  The variable `comment-multi-line' controls the
  242. choice (*note Comments::.).
  243.    Auto Fill mode does not refill entire paragraphs.  It can break
  244. lines but cannot merge lines.  Editing in the middle of a paragraph can
  245. result in a paragraph that is not correctly filled.  The easiest way to
  246. make the paragraph properly filled again is using an explicit fill
  247. commands.
  248.    Many users like Auto Fill mode and want to use it in all text files.
  249. The section on init files explains how you can arrange this permanently
  250. for yourself.  *Note Init File::.
  251. File: lemacs,  Node: Fill Commands,  Next: Fill Prefix,  Prev: Auto Fill,  Up: Filling
  252. Explicit Fill Commands
  253. ----------------------
  254. `M-q'
  255.      Fill current paragraph (`fill-paragraph').
  256. `M-g'
  257.      Fill each paragraph in the region (`fill-region').
  258. `C-x f'
  259.      Set the fill column (`set-fill-column').
  260. `M-x fill-region-as-paragraph.'
  261.      Fill the region, considering it as one paragraph.
  262. `M-s'
  263.      Center a line.
  264.    To refill a paragraph, use the command `Meta-q' (`fill-paragraph').
  265. It causes the paragraph containing point, or the one after point if
  266. point is between paragraphs, to be refilled.  All line breaks are
  267. removed, and new ones are inserted where necessary.  `M-q' can be
  268. undone with `C-_'.  *Note Undo::.
  269.    To refill many paragraphs, use `M-g' (`fill-region'), which divides
  270. the region into paragraphs and fills each of them.
  271.    `Meta-q' and `Meta-g' use the same criteria as `Meta-h' for finding
  272. paragraph boundaries (*note Paragraphs::.).  For more control, you can
  273. use `M-x fill-region-as-paragraph', which refills everything between
  274. point and mark.  This command recognizes only blank lines as paragraph
  275. separators.
  276.    A numeric argument to `M-g' or `M-q' causes it to "justify" the text
  277. as well as filling it.  Extra spaces are inserted to make the right
  278. margin line up exactly at the fill column.  To remove the extra spaces,
  279. use `M-q' or `M-g' with no argument.
  280.    The variable `auto-fill-inhibit-regexp'takes as a value a regexp to
  281. match lines that should not be auto-filled.
  282.    The command `Meta-s' (`center-line') centers the current line within
  283. the current fill column.  With an argument, it centers several lines
  284. individually and moves past them.
  285.    The maximum line width for filling is in the variable `fill-column'.
  286. Altering the value of `fill-column' makes it local to the current
  287. buffer; until then, the default value--initially 70--is in effect.
  288. *Note Locals::.
  289.    The easiest way to set `fill-column' is to use the command `C-x f'
  290. (`set-fill-column').  With no argument, it sets `fill-column' to the
  291. current horizontal position of point.  With a numeric argument, it uses
  292. that number as the new fill column.
  293. File: lemacs,  Node: Fill Prefix,  Prev: Fill Commands,  Up: Filling
  294. The Fill Prefix
  295. ---------------
  296.    To fill a paragraph in which each line starts with a special marker
  297. (which might be a few spaces, giving an indented paragraph), use the
  298. "fill prefix" feature.  The fill prefix is a string which is not
  299. included in filling.  Emacs expects every line to start with a fill
  300. prefix.
  301. `C-x .'
  302.      Set the fill prefix (`set-fill-prefix').
  303. `M-q'
  304.      Fill a paragraph using current fill prefix (`fill-paragraph').
  305. `M-x fill-individual-paragraphs'
  306.      Fill the region, considering each change of indentation as
  307.      starting a new paragraph.
  308.    To specify a fill prefix, move to a line that starts with the desired
  309. prefix, put point at the end of the prefix, and give the command
  310. `C-x .' (`set-fill-prefix').  That's a period after the `C-x'.  To turn
  311. off the fill prefix, specify an empty prefix: type `C-x .' with point
  312. at the beginning of a line.
  313.    When a fill prefix is in effect, the fill commands remove the fill
  314. prefix from each line before filling and insert it on each line after
  315. filling.  Auto Fill mode also inserts the fill prefix inserted on new
  316. lines it creates.  Lines that do not start with the fill prefix are
  317. considered to start paragraphs, both in `M-q' and the paragraph
  318. commands; this is just right if you are using paragraphs with hanging
  319. indentation (every line indented except the first one).  Lines which are
  320. blank or indented once the prefix is removed also separate or start
  321. paragraphs; this is what you want if you are writing multi-paragraph
  322. comments with a comment delimiter on each line.
  323.    The fill prefix is stored in the variable `fill-prefix'.  Its value
  324. is a string, or `nil' when there is no fill prefix.  This is a
  325. per-buffer variable; altering the variable affects only the current
  326. buffer, but there is a default value which you can change as well.
  327. *Note Locals::.
  328.    Another way to use fill prefixes is through `M-x
  329. fill-individual-paragraphs'.  This function divides the region into
  330. groups of consecutive lines with the same amount and kind of
  331. indentation and fills each group as a paragraph, using its indentation
  332. as a fill prefix.
  333. File: lemacs,  Node: Case,  Prev: Filling,  Up: Text
  334. Case Conversion Commands
  335. ========================
  336.    Emacs has commands for converting either a single word or any
  337. arbitrary range of text to upper case or to lower case.
  338. `M-l'
  339.      Convert following word to lower case (`downcase-word').
  340. `M-u'
  341.      Convert following word to upper case (`upcase-word').
  342. `M-c'
  343.      Capitalize the following word (`capitalize-word').
  344. `C-x C-l'
  345.      Convert region to lower case (`downcase-region').
  346. `C-x C-u'
  347.      Convert region to upper case (`upcase-region').
  348.    The word conversion commands are used most frequently.  `Meta-l'
  349. (`downcase-word') converts the word after point to lower case, moving
  350. past it.  Thus, repeating `Meta-l' converts successive words.  `Meta-u'
  351. (`upcase-word') converts to all capitals instead, while `Meta-c'
  352. (`capitalize-word') puts the first letter of the word into upper case
  353. and the rest into lower case.  The word conversion commands convert
  354. several words at once if given an argument.  They are especially
  355. convenient for converting a large amount of text from all upper case to
  356. mixed case: you can move through the text using `M-l', `M-u' or `M-c'
  357. on each word as appropriate, occasionally using `M-f' instead to skip a
  358. word.
  359.    When given a negative argument, the word case conversion commands
  360. apply to the appropriate number of words before point, but do not move
  361. point.  This is convenient when you have just typed a word in the wrong
  362. case: you can give the case conversion command and continue typing.
  363.    If a word case conversion command is given in the middle of a word,
  364. it applies only to the part of the word which follows point.  This is
  365. just like what `Meta-d' (`kill-word') does.  With a negative argument,
  366. case conversion applies only to the part of the word before point.
  367.    The other case conversion commands are `C-x C-u' (`upcase-region')
  368. and `C-x C-l' (`downcase-region'), which convert everything between
  369. point and mark to the specified case.  Point and mark do not move.
  370. File: lemacs,  Node: Programs,  Next: Running,  Prev: Text,  Up: Top
  371. Editing Programs
  372. ****************
  373.    Emacs has many commands designed to understand the syntax of
  374. programming languages such as Lisp and C.  These commands can
  375.    * Move over or kill balanced expressions or "sexps" (*note Lists::.).
  376.    * Move over or mark top-level balanced expressions ("defuns", in
  377.      Lisp; functions, in C).
  378.    * Show how parentheses balance (*note Matching::.).
  379.    * Insert, kill or align comments (*note Comments::.).
  380.    * Follow the usual indentation conventions of the language (*note
  381.      Grinding::.).
  382.    The commands available for words, sentences and paragraphs are
  383. useful in editing code even though their canonical application is for
  384. editing human language text.  Most symbols contain words (*note
  385. Words::.); sentences can be found in strings and comments (*note
  386. Sentences::.).  Paragraphs per se are not present in code, but the
  387. paragraph commands are useful anyway, because Lisp mode and C mode
  388. define paragraphs to begin and end at blank lines (*note
  389. Paragraphs::.).  Judicious use of blank lines to make the program
  390. clearer also provides interesting chunks of text for the paragraph
  391. commands to work on.
  392.    The selective display feature is useful for looking at the overall
  393. structure of a function (*note Selective Display::.).  This feature
  394. causes only the lines that are indented less than a specified amount to
  395. appear on the screen.
  396. * Menu:
  397. * Program Modes::       Major modes for editing programs.
  398. * Lists::               Expressions with balanced parentheses.
  399.                          There are editing commands to operate on them.
  400. * Defuns::              Each program is made up of separate functions.
  401.                          There are editing commands to operate on them.
  402. * Grinding::            Adjusting indentation to show the nesting.
  403. * Matching::            Insertion of a close-delimiter flashes matching open.
  404. * Comments::            Inserting, illing and aligning comments.
  405. * Balanced Editing::    Inserting two matching parentheses at once, etc.
  406. * Lisp Completion::     Completion on symbol names in Lisp code.
  407. * Documentation::       Getting documentation of functions you plan to call.
  408. * Change Log::          Maintaining a change history for your program.
  409. * Tags::                Go direct to any function in your program in one
  410.                          command.  Tags remembers which file it is in.
  411. * Fortran::        Fortran mode and its special features.
  412. File: lemacs,  Node: Program Modes,  Next: Lists,  Prev: Programs,  Up: Programs
  413. Major Modes for Programming Languages
  414. =====================================
  415.    Emacs has several major modes for the programming languages Lisp,
  416. Scheme (a variant of Lisp), C, Fortran and Muddle.  Ideally, a major
  417. mode should be implemented for each programming language you might want
  418. to edit with Emacs; but often the mode for one language can serve for
  419. other syntactically similar languages.  The language modes that exist
  420. are those that someone decided to take the trouble to write.
  421.    There are several variants of Lisp mode, which differ in the way they
  422. interface to Lisp execution.  *Note Lisp Modes::.
  423.    Each of the programming language modes defines the TAB key to run an
  424. indentation function that knows the indentation conventions of that
  425. language and updates the current line's indentation accordingly.  For
  426. example, in C mode TAB is bound to `c-indent-line'.  LFD is normally
  427. defined to do RET followed by TAB; thus, it too indents in a
  428. mode-specific fashion.
  429.    In most programming languages, indentation is likely to vary from
  430. line to line.  So the major modes for those languages rebind DEL to
  431. treat a tab as if it were the equivalent number of spaces (using the
  432. command `backward-delete-char-untabify').  This makes it possible to
  433. rub out indentation one column at a time without worrying whether it is
  434. made up of spaces or tabs.  In these modes, use `C-b C-d' to delete a
  435. tab character before point.
  436.    Programming language modes define paragraphs to be separated only by
  437. blank lines, so that the paragraph commands remain useful.  Auto Fill
  438. mode, if enabled in a programming language major mode, indents the new
  439. lines which it creates.
  440.    Turning on a major mode calls a user-supplied function called the
  441. "mode hook", which is the value of a Lisp variable.  For example,
  442. turning on C mode calls the value of the variable `c-mode-hook' if that
  443. value exists and is non-`nil'.  Mode hook variables for other
  444. programming language modes include `lisp-mode-hook',
  445. `emacs-lisp-mode-hook', `lisp-interaction-mode-hook',
  446. `scheme-mode-hook' and `muddle-mode-hook'.  The mode hook function
  447. receives no arguments.
  448. File: lemacs,  Node: Lists,  Next: Defuns,  Prev: Program Modes,  Up: Programs
  449. Lists and Sexps
  450. ===============
  451.    By convention, Emacs keys for dealing with balanced expressions are
  452. usually `Control-Meta-' characters.  They tend to be analogous in
  453. function to their `Control-' and `Meta-' equivalents.  These commands
  454. are usually thought of as pertaining to expressions in programming
  455. languages, but can be useful with any language in which some sort of
  456. parentheses exist (including English).
  457.    The commands fall into two classes.  Some commands deal only with
  458. "lists" (parenthetical groupings).  They see nothing except
  459. parentheses, brackets, braces (depending on what must balance in the
  460. language you are working with), and escape characters that might be used
  461. to quote those.
  462.    The other commands deal with expressions or "sexps".  The word `sexp'
  463. is derived from "s-expression", the term for an expression in Lisp.  In
  464. Emacs, the notion of `sexp' is not limited to Lisp.  It refers to an
  465. expression in the language  your program is written in.  Each
  466. programming language has its own major mode, which customizes the
  467. syntax tables so that expressions in that language count as sexps.
  468.    Sexps typically include symbols, numbers, and string constants, as
  469. well as anything contained in parentheses, brackets or braces.
  470.    In languages that use prefix and infix operators, such as C, it is
  471. not possible for all expressions to be sexps.  For example, C mode does
  472. not recognize `foo + bar' as an sexp, even though it is a C expression;
  473. it recognizes `foo' as one sexp and `bar' as another, with the `+' as
  474. punctuation between them.  This is a fundamental ambiguity: both `foo +
  475. bar' and `foo' are legitimate choices for the sexp to move over if
  476. point is at the `f'.  Note that `(foo + bar)' is a sexp in C mode.
  477.    Some languages have obscure forms of syntax for expressions that
  478. nobody has bothered to make Emacs understand properly.
  479. `C-M-f'
  480.      Move forward over an sexp (`forward-sexp').
  481. `C-M-b'
  482.      Move backward over an sexp (`backward-sexp').
  483. `C-M-k'
  484.      Kill sexp forward (`kill-sexp').
  485. `C-M-u'
  486.      Move up and backward in list structure (`backward-up-list').
  487. `C-M-d'
  488.      Move down and forward in list structure (`down-list').
  489. `C-M-n'
  490.      Move forward over a list (`forward-list').
  491. `C-M-p'
  492.      Move backward over a list (`backward-list').
  493. `C-M-t'
  494.      Transpose expressions (`transpose-sexps').
  495. `C-M-@'
  496.      Put mark after following expression (`mark-sexp').
  497.    To move forward over an sexp, use `C-M-f' (`forward-sexp').  If the
  498. first significant character after point is an opening delimiter (`(' in
  499. Lisp; `(', `[' or `{' in C), `C-M-f' moves past the matching closing
  500. delimiter.  If the character begins a symbol, string, or number,
  501. `C-M-f' moves over that.  If the character after point is a closing
  502. delimiter, `C-M-f' just moves past it.  (This last is not really moving
  503. across an sexp; it is an exception which is included in the definition
  504. of `C-M-f' because it is as useful a behavior as anyone can think of
  505. for that situation.)
  506.    The command `C-M-b' (`backward-sexp') moves backward over a sexp.
  507. The detailed rules are like those above for `C-M-f', but with
  508. directions reversed.  If there are any prefix characters (singlequote,
  509. backquote and comma, in Lisp) preceding the sexp, `C-M-b' moves back
  510. over them as well.
  511.    `C-M-f' or `C-M-b' with an argument repeats that operation the
  512. specified number of times; with a negative argument, it moves in the
  513. opposite direction.
  514.    In languages such as C where the comment-terminator can be
  515. recognized, the sexp commands move across comments as if they were
  516. whitespace.  In Lisp, and other languages where comments run until the
  517. end of a line, it is very difficult to ignore comments when parsing
  518. backwards; therefore, in such languages the sexp commands treat the
  519. text of comments as if it were code.
  520.    Killing an sexp at a time can be done with `C-M-k' (`kill-sexp').
  521. `C-M-k' kills the characters that `C-M-f' would move over.
  522.    The "list commands", `C-M-n' (`forward-list') and `C-M-p'
  523. (`backward-list'), move over lists like the sexp commands but skip over
  524. any number of other kinds of sexps (symbols, strings, etc).  In some
  525. situations, these commands are useful because they usually ignore
  526. comments, since the comments usually do not contain any lists.
  527.    `C-M-n' and `C-M-p' stay at the same level in parentheses, when that
  528. is possible.  To move up one (or N) levels, use `C-M-u'
  529. (`backward-up-list').  `C-M-u' moves backward up past one unmatched
  530. opening delimiter.  A positive argument serves as a repeat count; a
  531. negative argument reverses direction of motion and also requests
  532. repetition, so it moves forward and up one or more levels.
  533.    To move down in list structure, use `C-M-d' (`down-list').  In Lisp
  534. mode, where `(' is the only opening delimiter, this is nearly the same
  535. as searching for a `('.  An argument specifies the number of levels of
  536. parentheses to go down.
  537.    `C-M-t' (`transpose-sexps') drags the previous sexp across the next
  538. one.  An argument serves as a repeat count, and a negative argument
  539. drags backwards (thus canceling out the effect of `C-M-t' with a
  540. positive argument).  An argument of zero, rather than doing nothing,
  541. transposes the sexps ending after point and the mark.
  542.    To make the region be the next sexp in the buffer, use `C-M-@'
  543. (`mark-sexp') which sets the mark at the same place that `C-M-f' would
  544. move to.  `C-M-@' takes arguments like `C-M-f'.  In particular, a
  545. negative argument is useful for putting the mark at the beginning of
  546. the previous sexp.
  547.    The list and sexp commands' understanding of syntax is completely
  548. controlled by the syntax table.  Any character can, for example, be
  549. declared to be an opening delimiter and act like an open parenthesis.
  550. *Note Syntax::.
  551. File: lemacs,  Node: Defuns,  Next: Grinding,  Prev: Lists,  Up: Programs
  552. Defuns
  553. ======
  554.    In Emacs, a parenthetical grouping at the top level in the buffer is
  555. called a "defun".  The name derives from the fact that most top-level
  556. lists in a Lisp file are instances of the special form `defun', but in
  557. Emacs terminology, any top-level parenthetical grouping counts as a
  558. defun regardless of its contents, and regardless of the programming
  559. language in use.  For example, in C, the body of a function definition
  560. is a defun.
  561. `C-M-a'
  562.      Move to beginning of current or preceding defun
  563.      (`beginning-of-defun').
  564. `C-M-e'
  565.      Move to end of current or following defun (`end-of-defun').
  566. `C-M-h'
  567.      Put region around whole current or following defun (`mark-defun').
  568.    The commands to move to the beginning and end of the current defun
  569. are `C-M-a' (`beginning-of-defun') and `C-M-e' (`end-of-defun').
  570.    To operate on the current defun, use `C-M-h' (`mark-defun') which
  571. puts point at the beginning and the mark at the end of the current or
  572. next defun.  This is the easiest way to prepare for moving the defun to
  573. a different place.  In C mode, `C-M-h' runs the function
  574. `mark-c-function', which is almost the same as `mark-defun', but which
  575. backs up over the argument declarations, function name, and returned
  576. data type so that the entire C function is inside th e region.
  577.    To compile and evaluate the current defun, use `M-x
  578. elisp-compile-defun'. This function prints the results in the
  579. minibuffer. If you include an argument, it inserts the value in the
  580. current buffer after the defun.
  581.    Emacs assumes that any open-parenthesis found in the leftmost column
  582. is the start of a defun.  Therefore, never put an open-parenthesis at
  583. the left margin in a Lisp file unless it is the start of a top level
  584. list.  Never put an open-brace or other opening delimiter at the
  585. beginning of a line of C code unless it starts the body of a function.
  586. The most likely problem case is when you want an opening delimiter at
  587. the start of a line inside a string.  To avoid trouble, put an escape
  588. character (`\', in C and Emacs Lisp, `/' in some other Lisp dialects)
  589. before the opening delimiter.  It will not affect the contents of the
  590. string.
  591.    The original Emacs found defuns by moving upward a level of
  592. parentheses until there were no more levels to go up.  This always
  593. required scanning back to the beginning of the buffer, even for a small
  594. function.  To speed up the operation, Emacs was changed to assume that
  595. any `(' (or other character assigned the syntactic class of
  596. opening-delimiter) at the left margin is the start of a defun.  This
  597. heuristic is nearly always right and avoids the costly scan; however,
  598. it mandates the convention described above.
  599. File: lemacs,  Node: Grinding,  Next: Matching,  Prev: Defuns,  Up: Programs
  600. Indentation for Programs
  601. ========================
  602.    The best way to keep a program properly indented ("ground") is to
  603. use Emacs to re-indent it as you change the program.  Emacs has commands
  604. to indent properly either a single line, a specified number of lines, or
  605. all of the lines inside a single parenthetical grouping.
  606. * Menu:
  607. * Basic Indent::
  608. * Multi-line Indent::   Commands to reindent many lines at once.
  609. * Lisp Indent::        Specifying how each Lisp function should be indented.
  610. * C Indent::        Choosing an indentation style for C code.
  611. File: lemacs,  Node: Basic Indent,  Next: Multi-line Indent,  Prev: Grinding,  Up: Grinding
  612. Basic Program Indentation Commands
  613. ----------------------------------
  614. `TAB'
  615.      Adjust indentation of current line.
  616. `LFD'
  617.      Equivalent to RET followed by TAB (`newline-and-indent').
  618.    The basic indentation command is TAB, which gives the current line
  619. the correct indentation as determined from the previous lines.  The
  620. function that TAB runs depends on the major mode; it is
  621. `lisp-indent-line' in Lisp mode, `c-indent-line' in C mode, etc.  These
  622. functions understand different syntaxes for different languages, but
  623. they all do about the same thing.  TAB in any programming language
  624. major mode inserts or deletes whitespace at the beginning of the
  625. current line, independent of where point is in the line.  If point is
  626. inside the whitespace at the beginning of the line, TAB leaves it at
  627. the end of that whitespace; otherwise, TAB leaves point fixed with
  628. respect to the characters around it.
  629.    Use `C-q TAB' to insert a tab at point.
  630.    When entering a large amount of new code, use LFD
  631. (`newline-and-indent'), which is equivalent to a RET followed by a TAB.
  632. LFD creates a blank line, then gives it the appropriate indentation.
  633.    TAB indents the second and following lines of the body of a
  634. parenthetical grouping each under the preceding one; therefore, if you
  635. alter one line's indentation to be nonstandard, the lines below tend to
  636. follow it.  This is the right behavior in cases where the standard
  637. result of TAB does not look good.
  638.    Remember that Emacs assumes that an open-parenthesis, open-brace or
  639. other opening delimiter at the left margin (including the indentation
  640. routines) is the start of a function.  You should therefore never have
  641. an opening delimiter in column zero that is not the beginning of a
  642. function, not even inside a string.  This restriction is vital for
  643. making the indentation commands fast. *Note Defuns::, for more
  644. information on this behavior.
  645. File: lemacs,  Node: Multi-line Indent,  Next: Lisp Indent,  Prev: Basic Indent,  Up: Grinding
  646. Indenting Several Lines
  647. -----------------------
  648.    Several commands are available to re-indent several lines of code
  649. which have been altered or moved to a different level in a list
  650. structure,
  651. `C-M-q'
  652.      Re-indent all the lines within one list (`indent-sexp').
  653. `C-u TAB'
  654.      Shift an entire list rigidly sideways so that its first line is
  655.      properly indented.
  656. `C-M-\'
  657.      Re-indent all lines in the region (`indent-region').
  658.    To re-indent the contents of a single list, position point before the
  659. beginning of it and type `C-M-q'. This key is bound to `indent-sexp' in
  660. Lisp mode, `indent-c-exp' in C mode, and bound to other suitable
  661. functions in other modes.  The indentation of the line the sexp starts
  662. on is not changed; therefore, only the relative indentation within the
  663. list, and not its position, is changed.  To correct the position as
  664. well, type a TAB before `C-M-q'.
  665.    If the relative indentation within a list is correct but the
  666. indentation of its beginning is not, go to the line on which the list
  667. begins and type `C-u TAB'.  When you give TAB a numeric argument, it
  668. moves all the lines in the group, starting on the current line,
  669. sideways the same amount that the current line moves.  The command does
  670. not move lines that start inside strings, or C preprocessor lines when
  671. in C mode.
  672.    Another way to specify a range to be re-indented is with point and
  673. mark.  The command `C-M-\' (`indent-region') applies TAB to every line
  674. whose first character is between point and mark.
  675. File: lemacs,  Node: Lisp Indent,  Next: C Indent,  Prev: Multi-line Indent,  Up: Grinding
  676. Customizing Lisp Indentation
  677. ----------------------------
  678.    The indentation pattern for a Lisp expression can depend on the
  679. function called by the expression.  For each Lisp function, you can
  680. choose among several predefined patterns of indentation, or define an
  681. arbitrary one with a Lisp program.
  682.    The standard pattern of indentation is as follows: the second line
  683. of the expression is indented under the first argument, if that is on
  684. the same line as the beginning of the expression; otherwise, the second
  685. line is indented underneath the function name.  Each following line is
  686. indented under the previous line whose nesting depth is the same.
  687.    If the variable `lisp-indent-offset' is non-`nil', it overrides the
  688. usual indentation pattern for the second line of an expression, so that
  689. such lines are always indented `lisp-indent-offset' more columns than
  690. the containing list.
  691.    Certain functions override the standard pattern.  Functions whose
  692. names start with `def' always indent the second line by
  693. `lisp-body-indention' extra columns beyond the open-parenthesis
  694. starting the expression.
  695.    Individual functions can override the standard pattern in various
  696. ways, according to the `lisp-indent-function' property of the function
  697. name.  (Note: `lisp-indent-function' was formerly called
  698. `lisp-indent-hook').  There are four possibilities for this property:
  699. `nil'
  700.      This is the same as no property; the standard indentation pattern
  701.      is used.
  702. `defun'
  703.      The pattern used for function names that start with `def' is used
  704.      for this function also.
  705. a number, NUMBER
  706.      The first NUMBER arguments of the function are "distinguished"
  707.      arguments; the rest are considered the "body" of the expression.
  708.      A line in the expression is indented according to whether the
  709.      first argument on it is distinguished or not.  If the argument is
  710.      part of the body, the line is indented `lisp-body-indent' more
  711.      columns than the open-parenthesis starting the containing
  712.      expression.  If the argument is distinguished and is either the
  713.      first or second argument, it is indented twice that many extra
  714.      columns.  If the argument is distinguished and not the first or
  715.      second argument, the standard pattern is followed for that line.
  716. a symbol, SYMBOL
  717.      SYMBOL should be a function name; that function is called to
  718.      calculate the indentation of a line within this expression.  The
  719.      function receives two arguments:
  720.     STATE
  721.           The value returned by `parse-partial-sexp' (a Lisp primitive
  722.           for indentation and nesting computation) when it parses up to
  723.           the beginning of this line.
  724.     POS
  725.           The position at which the line being indented begins.
  726.      It should return either a number, which is the number of columns of
  727.      indentation for that line, or a list whose first element is such a
  728.      number.  The difference between returning a number and returning a
  729.      list is that a number says that all following lines at the same
  730.      nesting level should be indented just like this one; a list says
  731.      that following lines might call for different indentations.  This
  732.      makes a difference when the indentation is computed by `C-M-q'; if
  733.      the value is a number, `C-M-q' need not recalculate indentation
  734.      for the following lines until the end of the list.
  735. File: lemacs,  Node: C Indent,  Prev: Lisp Indent,  Up: Grinding
  736. Customizing C Indentation
  737. -------------------------
  738.    Two variables control which commands perform C indentation and when.
  739.    If `c-auto-newline' is non-`nil', newlines are inserted both before
  740. and after braces that you insert, and after colons and semicolons.
  741. Correct C indentation is done on all the lines that are made this way.
  742.    If `c-tab-always-indent' is non-`nil', the TAB command in C mode
  743. does indentation only if point is at the left margin or within the
  744. line's indentation.  If there is non-whitespace to the left of point,
  745. TAB just inserts a tab character in the buffer.  Normally, this
  746. variable is `nil', and TAB always reindents the current line.
  747.    C does not have anything analogous to particular function names for
  748. which special forms of indentation are desirable.  However, it has a
  749. different need for customization facilities: many different styles of C
  750. indentation are in common use.
  751.    There are six variables you can set to control the style that Emacs C
  752. mode will use.
  753. `c-indent-level'
  754.      Indentation of C statements within surrounding block.  The
  755.      surrounding block's indentation is the indentation of the line on
  756.      which the open-brace appears.
  757. `c-continued-statement-offset'
  758.      Extra indentation given to a substatement, such as the then-clause
  759.      of an if or body of a while.
  760. `c-brace-offset'
  761.      Extra indentation for lines that start with an open brace.
  762. `c-brace-imaginary-offset'
  763.      An open brace following other text is treated as if it were this
  764.      far to the right of the start of its line.
  765. `c-argdecl-indent'
  766.      Indentation level of declarations of C function arguments.
  767. `c-label-offset'
  768.      Extra indentation for a line that is a label, case, or default.
  769.    The variable `c-indent-level' controls the indentation for C
  770. statements with respect to the surrounding block.  In the example
  771.          {
  772.            foo ();
  773. the difference in indentation between the lines is `c-indent-level'.
  774. Its standard value is 2.
  775.    If the open-brace beginning the compound statement is not at the
  776. beginning of its line, the `c-indent-level' is added to the indentation
  777. of the line, not the column of the open-brace.  For example,
  778.      if (losing) {
  779.        do_this ();
  780. One popular indentation style is that which results from setting
  781. `c-indent-level' to 8 and putting open-braces at the end of a line in
  782. this way.  Another popular style prefers to put the open-brace on a
  783. separate line.
  784.    In fact, the value of the variable `c-brace-imaginary-offset' is
  785. also added to the indentation of such a statement.  Normally this
  786. variable is zero.  Think of this variable as the imaginary position of
  787. the open brace, relative to the first non-blank character on the line.
  788. By setting the variable to 4 and `c-indent-level' to 0, you can get
  789. this style:
  790.      if (x == y) {
  791.          do_it ();
  792.          }
  793.    When `c-indent-level' is zero, the statements inside most braces
  794. line up exactly under the open brace.  An exception are braces in column
  795. zero, like those surrounding a function's body.  The statements inside
  796. those braces are not placed at column zero.  Instead, `c-brace-offset'
  797. and `c-continued-statement-offset' (see below) are added to produce a
  798. typical offset between brace levels, and the statements are indented
  799. that far.
  800.    `c-continued-statement-offset' controls the extra indentation for a
  801. line that starts within a statement (but not within parentheses or
  802. brackets).  These lines are usually statements inside other statements,
  803. like the then-clauses of `if' statements and the bodies of `while'
  804. statements.  The `c-continued-statement-offset' parameter determines
  805. the difference in indentation between the two lines in
  806.      if (x == y)
  807.        do_it ();
  808. The default value for `c-continued-statement-offset' is 2.  Some
  809. popular indentation styles correspond to a value of zero for
  810. `c-continued-statement-offset'.
  811.    `c-brace-offset' is the extra indentation given to a line that
  812. starts with an open-brace.  Its standard value is zero; compare
  813.      if (x == y)
  814.        {
  815.      if (x == y)
  816.        do_it ();
  817. if you set `c-brace-offset' to 4, the first example becomes
  818.      if (x == y)
  819.            {
  820.    `c-argdecl-indent' controls the indentation of declarations of the
  821. arguments of a C function.  It is absolute: argument declarations
  822. receive exactly `c-argdecl-indent' spaces.  The standard value is 5 and
  823. results in code like this:
  824.      char *
  825.      index (string, char)
  826.           char *string;
  827.           int char;
  828.    `c-label-offset' is the extra indentation given to a line that
  829. contains a label, a case statement, or a `default:' statement.  Its
  830. standard value is -2 and results in code like this
  831.      switch (c)
  832.        {
  833.        case 'x':
  834. If `c-label-offset' were zero, the same code would be indented as
  835.      switch (c)
  836.        {
  837.          case 'x':
  838. This example assumes that the other variables above also have their
  839. default values.
  840.    Using the indentation style produced by the default settings of the
  841. variables just discussed, and putting open braces on separate lines
  842. produces clear and readable files.  For an example, look at any of the C
  843. source files of GNU Emacs.
  844. File: lemacs,  Node: Matching,  Next: Comments,  Prev: Grinding,  Up: Programs
  845. Automatic Display of Matching Parentheses
  846. =========================================
  847.    The Emacs parenthesis-matching feature shows you automatically how
  848. parentheses match in the text.  Whenever a self-inserting character that
  849. is a closing delimiter is typed, the cursor moves momentarily to the
  850. location of the matching opening delimiter, provided that is visible on
  851. the screen.  If it is not on the screen, some text starting with that
  852. opening delimiter is displayed in the echo area.  Either way, you see
  853. the grouping you are closing off.
  854.    In Lisp, automatic matching applies only to parentheses.  In C, it
  855. also applies to braces and brackets.  Emacs knows which characters to
  856. regard as matching delimiters based on the syntax table set by the major
  857. mode.  *Note Syntax::.
  858.    If the opening delimiter and closing delimiter are mismatched--such
  859. as in `[x)'--the echo area displays a warning message.  The correct
  860. matches are specified in the syntax table.
  861.    Two variables control parenthesis matching displays.
  862. `blink-matching-paren' turns the feature on or off: `nil' turns it off,
  863. but the default is `t' to turn match display on.
  864. `blink-matching-paren-distance' specifies how many characters back
  865. Emacs searches to find a matching opening delimiter.  If the match is
  866. not found in the specified region, scanning stops, and nothing is
  867. displayed.  This prevents wasting lots of time scanning when there is no
  868. match.  The default is 4000.
  869.